JS fixes

This is totally a **WIP**, but it works for me in both Firefox and Chome without any TypeErrors.

/CC @connor @connors @fat 

Any suggestions are welcome.

PS. IE is broken after #446