Sort fields in the groups as well as the groups themselves.  Utilize Drupal core Form API functions instead of re-inventing the wheel.