Code described in JHC paper