Fixing a bunch of segfaults