Fixed calculation of U and V