Added the error handling code