refactor of codes