Some more refactoring, fixes #8