Added a function for handling errors coming externally.