fixed player loop and end condition