[wip] Quite some refactoring.