rearrange and cleanup