Improved detection of script location