Resolving segfault problems (not finished)