Attemped fix at segfault