Fix potential divide by zero errors
Merge pull request #361 from staer/patch-1

Fix potential divide by zero errors