More refactoring to get to a point where we can start using unit tests