added dynamic allocation

segmentation error gone!!