Added a flag which checks if a middleware has already been run, and if so, prevents it from running again.