Added error handler for logging errors