Modified for-loops to increment over blocks in mainMemory.