improve writer and reader
add connect call, and premise of error handling
misc code movement