Post refactoring

this is just @guiblondeau's previous PR, with some merges done to fix up some things. This has been reviewed in the previous PR, so I'm merging this