sort the anchors based on the offset, then we replace the anchors from the end
still having bug in creating the anchors