I had to put this whole block of code (lines 9-16) through js2coffee to fully grok what was happening, there is some coffee magic.