slightly modified version of Stephen Wright's MLHKA