Refactor path cleaning