Huigol's implementation