added function for handling errors