Various fixes for exception handling