added function to remove empty groups