Changed error handling from string-type errors to object-type errors.