fixed segmentation fault due to null pointer