Fixed null checking bug