Move reference gathering to a separate function