Corrected calculation of z rotation of matrix.