Moving middleware loader to correct initialization