Merge pull request #19 from bradbishop/refactor

Refactoring and fixes.