refactor nullptr check