Fixed recursive closure capture, now checks intermediate scopes for variable declaration