refactor core game functions