Added correct handling of division by zero.