Remove endl and tailing whitespaces