corrected a null checking bug