Added ability to wait for correct shutdown by waiting for closed channel