fixed several JS bugs.