move check that a var is defined to typecheck

(not sure what I was thinking before...)