Moved middleware to sub