the duplication function now correctly shifts the new elements