Correcting middleware scope issue