fix some bugs and some changes on SO