Declare i in main(), not in for's
Free lines in the end