refactored to have cleaner state management upon shutdown, by using close(channel) semantics