It's probably worth a comment to mention that <code>ni</code> is not <code>names.size()</code> and so <code>names.insert(ni++,n);</code> is not equivalent to <code>names.append(n);</code>