add game engine code and refactor parts of other code