Fixed the isnan function call and added back in the g_count that was removed from previous commit.