refactored Read and Write on channels to use common code