added some additional logic for the find_path function