Fixing javascript bugs