Thoroughly commented the code and optimized the reconciliation algorithm to go faster

Other bug fixes along the way too, as I was commenting the code.