minor improvements to exception handling