Improved script
Refactoring