Fixing javascript bug