Fixed doing it wrong

Realized I was computing the wrong thing - rewrote everything. This was
actually a lot faster to solve now that I knew what I was supposed to be
doing!
Merging