A lot of refactoring, fixes #3