Fixed a bug with two levels deep of reference expansions.