Fix errors in computation of DV; some code cleanup.