Segfaulting after refactoring