improve stdin/stdout/optparse handling