Cleanup

Initial restructuring of code