Fix more scope issues.

I think I understand this now. Functions defined with 'def' are always
defined in the top-level scope. Which is pretty dumb.