moved resolve_ref inside Context class