These three lines can be replaced with:

    refs = Array(refs)

which will keep an Array as just an Array (it won't nest).