Fixed segfaults and test. How did I miss it...