Added removal of variables which are no longer in scope, global variables do not get removed.