Fix bug in skip stages

Out of scope variables were sneaking into the condition via
replacing a for loop of extent one with its min during analysis.