$i needs to be initialised