fix bugs in weiqi's code