add check null and refactor method