Refactor static checking and fix things.

Lexical scopes work properly, and function names with the immediate left
assign hack work properly in both scopes. Tests fixed.