BUG: Prevent division by zero. Closes #650.
Merge pull request #4591 from szpy/bugfixes

BUG: Prevent division by zero. Closes #650.