Refactored all for-loops to c++11.