Add some error checks, prevent divide by zero.