Better atexit functionality for early failures

Closes #323
Merge pull request #325 from ChrisBeaumont/323

Better tracebacks for errors during setup