Various fixes to socket communication