fixed error in diff function