refactoring the diff adjust code.