now fully supports STDIN, solved fgets hang