Fixing vicious JS bug