better handling of exceptions