fixed bugs which will cause segmentation 11.