Added error handling code.