Given that you just trimmed whitespace before the loop, this is going to be redundant.  I think you can remove the trimLeadingWhitespace of as on 84/85 and just let these loops inside the main loop handle that.