Refactor out duplicate code using extract method