Major algorithmic optimizations to mining in momentum.cpp.

The full algorithmic optimizations are now contained in this push request.  See comment below.