add check for empty groups

Check to make sure that groups is not nil before attempting to set it.