fix generate_bell with recursive algorithm

TODO: replace with a non-recursive algorithm.
use non-recursive algorithm for generate_bell
Merge pull request #2694 from smichr/bell

fix generate_bell