moved waitgroup wait