separated main read loop out, added tcp keep alives