Refactored uses of <iterator> and <algorithm> to avoid dependencies where possible.