Improved sanitizePath and removed unessesary rethrows