fixed bug where it was printing the last line twice