Added divide by zero check