Image caption Security officers watch over protesters making a point outside a courthouse in Beijing

We had been in the taxi for about 20 minutes when the driver took a call, just as we were about to get out of the car.

He seemed confused as he told the caller exactly where we were. "They're just getting out of the taxi now," he told the person on the other end of the line, talking about us.

China's security machine was watching the BBC - just as it monitors other foreign journalists, activists and potential enemies of the state.

Keeping tabs on these people is just one part of a vast domestic law enforcement apparatus that now costs more than the military in China.

This army of security personnel is charged with maintaining "harmony and stability", two key watchwords under President Hu Jintao.

Secretive ministry

After getting out of the taxi, we were tailed by plainclothes security operatives across the city of Chengdu in Sichuan province, where we were trying to report on Tibetan unrest.

We got into another taxi to try to shake them, making a series of quick turns to see if they would follow. They did.

Security personnel tracked us across the city. We kept spotting the same people at different points and different times.

China's internal security system was expected to cost 624bn yuan ($99bn, £63bn) last year, slightly more than the 601bn yuan earmarked for the military.

Image caption Activist Yu Jie, now in the US, says he suffered from illegal house arrest, torture and surveillance

This is the first time these operations have cost more than the armed forces.

The money is not only spent on the police, courts and jails, but also on government organisations that are charged with keeping an eye on those who are thought to threaten the Communist Party-ruled state.

The Ministry of Public Security is responsible for day-to-day police activities, although it is also involved in watching activists.

There is also the Ministry of State Security, a far more secretive organisation that does not have its own website, even in an age when the Chinese authorities have embraced the internet.

There is little public information about this ministry.

One website, run by the Communist Party newspaper the People's Daily, has some details in a section about China's government departments.

Unfortunately, the most recent article here dates from 2007, announcing the appointment of a new head for the ministry, Geng Huichang.

Baidu, a Chinese web portal, has a little more information.

It says the ministry is divided into 16 sections, with the Ninth Bureau responsible for "monitoring internal reactionary groups".

'Little accountability'

Another organisation in charge of internal security is the People's Armed Police, a part of China's armed forces. It has 660,000 personnel, perhaps more.

This force is often at the forefront of controlling unrest in Tibetan areas and Xinjiang, a region in the far north-west of China with a large Muslim population.

The BBC's trip to Sichuan offers an example of just how many government departments can get involved in monitoring undesirable elements.

We were stopped in one county by a gang of watchers, who had come from the local public security bureau - the police - the propaganda department and the foreign affairs department.

Different countries at different times have identified and monitored citizens who they believe are a threat to the state.

We can dig a pit and bury you alive in half an hour. Security chief , To activist Yu Jie

But Murray Scot Tanner, an expert in Chinese security issues at the US research institute CNA, said there are some major differences in China.

"One of them is the vast difference in transparency and accountability compared to Western democracies," he said.

The laws that Chinese dissidents are often charged with also offer scope for abuse.

"These are some of the least well-defined and least clear in the Chinese legal system and so are subject to arbitrary law enforcement," he said.

There are plenty of examples of security operations against Chinese activists that seem to have been based on shaky legal ground.

Author and dissident Yu Jie, who has just fled China to the United States with his family, has spoken about his experiences.

"Illegal house arrest, torture, surveillance, tracking and being taken on 'trips' became part of my everyday life," he said in a statement shortly after arriving in America.

In one episode, he spoke of being hooded, taken away and subjected to a frightening ordeal by official security personnel.

Mr Yu said the man in charge made it clear what could happen to him if he did not co-operate.

"If the order comes from above, we can dig a pit and bury you alive in half an hour and no-one on Earth would know," the security boss allegedly told the activist.

Other dissidents tell similar - equally harrowing - stories.

Over recent years, the Chinese government seems to have become more zealous in keeping control of government critics in the name of maintaining social stability.

It is a theme that President Hu has talked about often.

In a speech last February, he said the goal was to "solve prominent problems that might harm the harmony and stability of society".

Prof Joseph Cheng, of the City University of Hong Kong, said the current Chinese leadership used several levers to maintain control.

For the vast majority of people who support the government, it has provided rising living standards through economic growth and an enhanced social security network.

"But there is a deliberate scheme to demonstrate that the state has an effective machine to crack down on those that disagree with the party," he added.