gongming: refactor and clean the code