Refactor to idiomatic JavaScript

About 25x faster in Chrome
About 8x faster in Safari
About 6x faster in Firefox
About 4x faster in IE
Merge pull request #1 from arv/cleanup

Refactor to idiomatic JavaScript