replace error listener with helper function