simplifying the stdin processing and fixing the error when there was no new line at the end of the file