Bug fixes. More tweaks and error trapping.