added some null checking