Fixed some bugs in the whitespace trimming