Improved laziness on reference resolution.
Minor fixes.
Increase testing code coverage.