move middleware into services