Bugfixes and minor mods.

Bugfixes to address a number of open issues.