added code to error handling