Fix pattern sorting