Make the math more resilient.
Merge pull request #55 from nubs/master

Make the math more resilient.