Refactored to make produceScope function