Fix build error and unit tests
Fix of by one errors - tests now pass