remove duplicate code with a method