fixed bugs : beam search generating correct tree