More robust NPE checking