removed tail space, and add necessary new line marks