Refactor to use channels instead of mutexes.