remove newlines only when needed.