fix bugs in function end game