Added tests and refactored the game code