added checks for null

please check it