Segfault fix, looks ugly