Removed duplication in middleware