fixed cleaning of vars linked by reference