refactor code to comments from  qiangxue