Fixed various bugs in communication code