Fix stack overflow on invalidate, remove last token properly on 2.x