Move middleware to own package