Changed method to trim empty lines in the end.