Modified the behaviour of sort. Now sorts within groups rather than global sort.