Fixed bug in handling errors.