Some minor improvements in exception handling and tweaks.