Fixed infinite iterator, refactored beam search into separate file