refactor code