Changing variable names and clearing the line str in the beggining of the loop.