Improved path handling in scripts