compact array before creating hash to avoid deprecation warning
make template thread safe