A few general segfault fixes