bugfixes from Alec Edworthy