Refactored script processing.