fixed stdin reader logic