collect references that haven't been declared in scope - fixes #173 and fixes #175