Fixing bugs in js