fixing exception handling code