All code by Ian Macdonald <ian@caliban.org>
