Still seg faulting, but works more properly