Added error handling and error middleware.