Moved middleware into its own package