Everywhere in this code prevHash == input.PrevHash, thus we can easily move some common code out of the loop saving on DB accesses and serialization/deserialization.