Fix division by zero bug