Restructure ai.c for merging