Rewrote the script in CoffeeScript with the exact same functionality as master.