Various fixes/enhancements

Broken into three commits now (as suggested), and the tests pass.