Fixed some segfaults