fix divide by zero error

Fixes #4325