refactor to use readLine instead of readAll