fix non-invertible matrices