write to stdout correctly