Following the successes in the 1850s in the provinces of Guangxi, Hunan and Hubei, and the capture of Nanjing in 1853 the rebel advance had slowed. For some years, the Taipings gradually advanced eastwards, but eventually they came close enough to Shanghai to alarm the European inhabitants. A militia of Europeans and Asians was raised for the defence of the city and placed under the command of an American, Frederick Townsend Ward, and occupied the country to the west of Shanghai. The British arrived at a crucial time. Staveley decided to clear the rebels within of Shanghai in co-operation with Ward and a small French force. Gordon was attached to his staff as engineer officer. Jiading, northwest suburb of present Shanghai, Qingpu and other towns were occupied, and the area was fairly cleared of rebels by the end of 1862.