Checking in before doing some major refactoring

Checking code before splitting the core into 3 modules: one with the event loop,
one with direct commands and one with indirect commands.