Extract setup of application middleware to new method