avoid extra PATH cleaning when not needed, update #1446
extract PATH extra slashes cleaning to separate function, update #1446