Properly iterate through array