better working path search algorithm