refactor to avoid duplication