In 1761, Alexander Dalrymple, an officer of the British East India Company, concluded an agreement with the Sultan of Sulu to allow him to set up a trading post for the first time in northern Borneo, although this was to prove a failure. Following the British occupation of Manila in 1763, the British freed the Sultan Alimuddin from Spanish colonisers and allowed him to return to his throne; this was welcomed by the Sulu people and by 1765, Dalrymple managed to obtain the island, having concluded a Treaty of Alliance and Commerce with the Sultan of Sulu by the willing of Sultan Alimuddin as a sign of gratitude for the British aid. A small British factory was then established in 1773 on Balambangan Island, a tiny island situated off the north coast of Borneo. The British saw the island as a suitable location to control the trade route in the East, capable of diverting trade from the Spanish port of Manila and the Dutch port of Batavia especially with its strategic location between the South China Sea and Sulu Sea. But the British abandoned the island two years later when the Sulu pirates began attacking. This forced the British to seek refuge in Brunei in 1774, and to abandon temporarily their attempts to find alternative sites for the factory. Although an attempt was made in 1803 to turn Balambangan into a military station, the British did not re-establish any further trading posts in the region until Stamford Raffles founded Singapore in 1819.