improved path string sanitation