refactored codebase and started writing unit tests.
refactoring, tests.