Lock things properly and close channels at the right time so everything works