Added more tests around higher level functionality
Refactored many areas of code