Remove whitespaces before add ending newline

Fix there in only whitespace in last line. And insert ending new line after trailing.