Pass closures through classdefs

Ie if a class is defined in a function, and that class contains
a function which references variables from the enclosing function,
previously the classdef would not pass the closure through and
things would fail.

Now classdefs (and other scopes) can pass through closures even if
they don't add their own variables to the closured-set.

Also, fix some bugs along the way.