Added more effective error handler