add waitgroups to make sure the goroutine finishes first