Changed for-each loops to for-loops