Fix javascript, fixes #222
Move JS to bottom of file