REFACTOR: move common functions