minor fixes
refactor tcp handling, fix #280