Fixed bug in tangent calculations