improve for-each-ref test script