Remove undeclared variable in wrong scope