refactor zDiff code