updating the z terms using cpp