Cleanup g_item.c and add sanity checks