Lots of cleanup and refactoring, no logic changes
Merge pull request #26 from mpath/refactor

Lots of cleanup and refactoring, no logic changes