Added proper middleware function.