Refactor code

Fixes #19.
The length caching would be an improvement. But declaring i at the top is definitely a good practice (makes switching between vanilla JS and Coffee easier). Let's declare both up front, wdyt?