remove unused variables and fix a bug