Found the cause of the segfault.Can't state for sure that this removes the bug