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

Make the math more resilient.