Fixed segmentation fault

Made changes to data structures and pointers to avoid seg faults