Added refId, fixed ref, handle null object