rearrange and categorise