Heavily refactor and include new tests.
Merge pull request #4 from loweoj/master

Finish and include new tests.