Changed all the foreach loops to for loops in order to prevent garbage collector problems in iOS platform.