Correcting the bugs and issues pointed out in liancheng's very helpful comments.