Added group calculating algorithm and choosing group functionality.