Fixed bad pointer usage
Fixed some segmentation faults