Fix reference handling for closures.

Add SmallVector class which should make most argument passing stay on
the stack.