fixes to code and tests