Fix segfaults in unit tests

now some tests still fail, but not crash anymore