Vastly improved performance

Now runs only ~.3 seconds slower than the old version with around 5-6x
as much memory use.