dev function writeDifferencese + unit tests