trElms[trlen] is used multiple times so should cache it in a local variable to save clock cycles.