added some (ugly) segfault mangement