refactored script