Fix NPE logic