Fixed issue with pop vs shift in order sensitive operation