refactor duplication into method