Some more refactoring to make unit testing easier, and more unit tests added
Some more tests