Moved most of engine.lua to registry.lua