replace references with object where appropriate