corrects pop and shift problem