Cleanup g_func.c and add sanity checks