Refactored code for null scopes