Various fixes/enhancements

Broken into three commits now (as suggested), and the tests pass.
Why is the `reduce` version better than `flatten`?