An improved calculation of critical magnetic shear in an inhomogeneous plasma