Keep .length accurate

If you just set it to elements.length at the beginning, it won't update as the length changes.