fixed segfaults and pointers