fix waitgroup logic