refactored the scope destruction