Bug fixes found during writing of unit tests