Removed some raw loops and replaced them by algorithms and boost fusion magic.