Added support for references.
Fixed references with mocha tests.