fixed errors in calculating B matrix and dR_du