cleaned up socket reading and timeout handling