added some null checks