refactor to eliminate duplication