Added error handling middleware