refactor game engine