rewrote algorithm. Soooo much better.