remove more duplicated code, and fixed add group