Few segfault fixes