Merge pull request #72 from lshift/issue71

First attempt at refactoring code
Merge branch 'master' into issue71