Fixing a javascript bug