Fixed problem that prevented to save refences during discovering. The incoming references were not cleaned and therefore were generating conflicts about ids.