Database trigger function fix