Improved panic handling

Fixes #65