consolidate error function