Reduced scope of varoius variables in ai_cmd.c