int writeIdx = startLevel;
for (int level = startLevel; level < currentLevel; level++) {
final StoredBool var = variableStack[level];
final boolean val = valueStack[level];
final int stamp = stampStack[level];
var.overrideTimeStamp(prevWorld);// update the stamp of the variable (current stamp refers to a world that no longer exists)
if (stamp != prevWorld) {
// shift the update if needed
if (writeIdx != level) {
valueStack[writeIdx] = val;
variableStack[writeIdx] = var;