Game loop finally works correctly. Will merge to master