using mutex over channels, and some other minor cleanups