Updated handling of errors