logic makes sense to me, but segmentation fault on creating array. cannot fix it