Re- wrote the code. Faster, simpler, less memory.