fixed bugs in JS