refactor and use earliest scope