fix to --stdin mode and minor cleanup