split diff computation into many small functions