Some tidying up in g_ai.c