#3 some refactoring and started creating tests.