better refactor the 3 common conditions into a separate if to ease readability