Enhanced beam search, fixed path backtracing bug