Refactored script.