imroved exception handling