Rename variable i
Pull out file handling code into class