add STDIN support and clean some codes