Misc work
Move more logic to the core engine.