refactor code remove duplicate