improved null checking