fix some bugs. clear some unused variables. stable