added hierarchical sorting for rules