Switched to using channels rather than locks.

Suggestion by @mrb.