Improved exceptions handling, fixes #11