Added more unit tests and refactoring to help with unit testing