fix some bugs and rename a var