fixed output bug for last line