How can I get rid of the last line break in the output? Could that be the problem?