maintain Byzantine authority. The Gaetans received their first imperial Byzantine hypati around the time of the Beneventan civil war. While the first hypati remained Byzantine loyals, in 866, the sudden appearance of a new dynasty under Docibilis I represented Gaeta's move from Byzantium towards independence. The first elected ruler of Amalfi was a prefect appearing in 839, simultaneous with the death of Sicard and the appearance of a Gaetan hyaptus. However, Naples, Gaeta, Amalfi, the Tyrrhenian cities, and Venice (in North Italy) retained some allegiance to Byzantium until the 11th century-long after becoming de facto independent. Period of confusion (849–915) The period following the Beneventan civil war was one of confusion, brought on by the independence movements in the various cities and provinces and by the Saracen onslaught. In Salerno, a palace coup removed Siconulf's successor Sico II in 853 and destabilised that principality until a new dynasty, the Dauferidi, came to power in 861. In 852, the Saracens took Bari and founded an emirate there. Greek power being significantly threatened, as well as Adriatic commerce, the Byzantine emperor requested an alliance from Louis II of Italy. Similarly, the new prince of Benevento, Adelchis, an independent-minded ruler, also sought his aid. Louis came down and retook Bari in 871 after a great siege. Louis then tried to set up greater control over all the south by garrisoning his troops in Beneventan fortresses. The response of Adelchis to this action was to imprison and rob the emperor while he was staying the princely palace at Benevento. A month later, the Saracens had landed with a new invasive force and Adelchis released Louis to lead the armies against it. Adelchis forced Louis to vow never to re-enter Benevento with an army or to take revenge for his detention. Louis went to Rome in 872 and was released from his oath by Pope Adrian II on 28 May. His attempts to punish Adelchis were not very successful. Adelchis vacillated between nominal fealty to the Carolingian and Byzantine emperors, but, in fact, by his alterations to the Edictum Rothari, he acknowledged himself as the legitimate Lombard "king." The successors of Adelchis were weak and the principality of Benevento declined just as Salernitan power was beginning to make itself felt. Guaifer of Salerno was on friendly terms with the Saracens, a habit which annoyed the popes and often put a ruler at odds with his