fixed bug with catching exceptions