Moar refactoring and bugfixing

will it ever end???