Cleanup g_trigger.c and add sanity checks