enh: simplified algorithm, tests now pass