revised for stdin stdout