Improvements to TCP connection handling