Refactored script processing and running.