resolved segmentation error 11 by adding if null check