copied Xianglian's code to the right places