Using the global i is not a good idea for iteration