handle reading and writing tcp data better