Fix a bug where a division by zero can occur.