refactor gamelogic