merge iaint's patch to rewrite path