Refactor how the sorting controls are generated to keep things DRY.