Fixes #9. Other misc. refactoring changes.