refix copy algorithm