new hd-d function now working (but is extremely slow on large texts)