Fix a problem with referencing.
Improve tests.