Fix varref, add tests.