why don't you save the length into a separate var? or why not using dynamic arrays?