Fixing some big issues

There were some major issues when I had the JS in a different file
(wouldn't run correctly) so I put it all together again