Address most of jam's comments (the rest will be addressed next).
Cleanup after refactoring.