cleaning up error handling code