Refactor topic hierarchy creation