refactored game from main.cpp