inner loop fixed (again...)