refactoring of variable and rules sorting functions and sorting fixes for groups and pages
invalid idention fix