fixing some bugs, adding group function