added support for referenced documents