More work on main game loop