Replace g_assert with some kind of error handling