Fix hash_refs greed when looking for template references