First attempt at refactoring code
Merge pull request #72 from lshift/issue71

First attempt at refactoring code