Improved null checking