Fix to error handling