I don't have the context to fully understand all this stuff so I'm going comment on whitespace :p. Just a couple things I find help readability are always having spaces around `+`, `=`, etc. (so like in your string concatenation and in for-loops `var i = 0;`. And then also the `function` keyword should have a space after it even when it's an anonymous function, which you did everywhere except once at the top. But whatever, fix at your leisure