Move i initialization out