Modified the error handling