updated HK algorith from
https://github.com/MelkoCollective/extended_hk
commit 5892ff451f1f014b6c6bc76681476a2e84527d51