fix some bugs due to unused variables and bad call for modified functions