refactored code, abstract the game logic into separated class