Updated code. SegFaults present