refactored path handler