Handle divide by zero. Fixes #481