Post segfault fixes

Fixes from the segfaulthunt pull request, closing that one