Refactor for code duplication