Only add non-empty group

sorted function has parameter "key"