refactored path cleaning