changed error handling code