Refactor and cleanup of script runner.