refactor the snake game