Improved path handling