Non-Muslim communities living under Islamic rule were allowed to follow their own laws. The government kept out of their internal legal affairs, except when there was a dispute between people of different religions. Such cases were handled by a qadi. When that happened, sharia rules gave Muslims some legal advantages over non-Muslims. However, non-Muslims often won cases against Muslims and even against high government officials, because people thought that sharia was a reflection of divine justice which should defend the weak against the powerful.