Fixed tangent calculations

Put in a new tangent calculation, as the old one returned NaN and
infinite quite often on a few models