corrected stack invariant