Rework input-file-reading code

Can now handle a newline at the end of the file