Starting to upgrade
Assorted code cleanup
Cleaning up more logic
Fixed #6
Finishing upgrade