refactoring middleware check header