More refactoring, closing this branch afterwards.