Corrected the null pointer exception checks.