fix divide by zero error

Fixes #4298