add divide by zero anremove repeating of code