Remove use of fromJust via StateT.
Substantial rewrite: fixed idiotic bug that had gone unnoticed for several versions, rewrote inner loop w/ ST, added strictness annotations, and made some random style changes.