Lots of refactoring, closes #11