Sorting Changes
implemented code optimizations