Only capture locals that are directly referred to by the function

Fixes #10