added some null checks
added some null checks