rearrange by function