added rule sorting