Improve logic for declaring default middleware.