refactoring logic and game