extracted duplicate code