added error handling code