build up the references hierarchy