Move the waitgroup.Add outside the goroutine

* This avoids a potential race condition