refactor ai spec and gamestate functions