Pr/63

Rebased version of #63 with some extra refactoring.

And test fixes and what not