Refactored path search procedure