add rearrange function (not finish)