remove unused variables and fix scope error.