corrected null pointer logic