bugfixes from Jeff Finucane <jeff@cmh.net>, thanks!