Replaced WaitGroup with sync.atomic. Added comments.