remove duplicate error handling code