Various attempts to fix space leaks in beam search. Improved, but not fixed.