I have two questions: first, have you tried concatenating the input instead of going through line by line to see if you can get this to work that way? And second, if you are going to continue with the line-by-line approach, why load the whole file into memory at once?