Added better exception support, and tests

fixes #4