Added extra check for getline successfully reading a line