Started building unit tests and refactoring