Move duplicate code to separate method