Refactor diff code into new module