Fix division by zero, make use of exceptions.