fix main loop in core.lua