porting and debugging segfault