C++11 todo fixes
This merge request addresses all the todo notes left as part of the C++11 upgrade to move from raw loops to algorithms.
Some interesting side effects: remove several instances of dynamic allocations and removed some dead code. Lots of complicated logic drops out so readability should be improved.