fixed some complicated statements, but segmentation fault is generated