refactoring waiting for channels