refactor: extract function