Fix a couple of bugs in the sending/receiving threads