refactor script_command context grabbing