Third pass working
Refactoring and adding initial tests