improvements on tcp handling