added divide by zero check