fixed some bugs with exception handling