Refactor to reduce duplication