Sort out mess with automatically converted foreach loops