fix some code style and bug from yaowenbin's reviews.