refactor some duplication