tests now passing, fixes #18
Merge pull request #20 from djuretic/rewrite

Tests now passing