attempted bug fixes for group function (untested)