Improve tcp buffer handling