Bug fix round 2

Qian's bug fix round 2.