better handling of exceptions

relates to #161