Merged r9875 from trunk.
Tests should not change settings.
Removed unused helper.
Adds a scope for sorting groups.
Code cleanup.
Fixed test failure.
Test failure.