Improved detection of script name