refactor and fix npe