Reorder all elements according to order of appearance in code