avoid division by zero
changes after review
Merge pull request #515 from dlatnikov/JFG_306_division_by_zero

avoid division by zero