implement patterns reordering