fixed a bunch of js bugs