implemented rudimentary beam search