[WIP] More massive refactoring