Refactor diff functions