Helper functions for group calculation