[WIP] Refactoring

Also fixes #26