Improve support for references.

Change-Id: I86cb599c11f4c65271be2a270f8ed3ae6d30c63e