Added error handler for debugging