Finish code refactoring

Fixes #5 and #9
This is so much nicer.