Start major refactoring, still some quirks left