fixed off-by-one error in readNode and writeNode