Small fixes to code, unit tests now pass