updated error handling