refactor to avoid nullptr