refactor $script