Minor refactoring and cleanups.
Implement #57 and #58