Added stats factored out main loop to core.js