improve addnodes and addreferences struct and serialization

Addnodes and Addreferences method works. It is not entirely complete but good enough for now. Please review and merge