rearranging data arrays