Improve diff function