Added serialization of references. Should fix #528
Merge pull request #529 from khellang/serialize-references

Added serialization of references