create groups function