Add game states and refactor code