[READY] Socket issues fixes and tidy up

Fixes issues with all the data being sent down the socket at once and a number of other issues.