refactored middleware to config