fix-NPE code refactor