Merge pull request #33 from johnb30/master

Refactoring and bug fixes