Final pull before submission

Major refactor for code cleanup
Caught a minor bug