Code cleanup: replace some loops with <algorithm>

For beauty and readability! ;-)