Fix error in setting up W matrix.