Added error-handling code.