Made angle calculation less sensitive to floating point errors