Fix failing tests and segfault