Check r and p against zero before dividing
Merge pull request #149 from jvarho/divide-by-zero-fix

Check r and p against zero before dividing