used enumerate function for looping, removed local index variables