this piece of code is identical to the previous one. Either factor it out into a separate method or, better, merge these two checks with a disjunction of conditions