re-wrote main game loop