Script refactored