A temple was first built at the site around 850 CE by Rakai Pikatan and expanded extensively by King Lokapala and Balitung Maha Sambu the Sanjaya king of the Mataram Kingdom. According to the Shivagrha inscription of 856 CE, the temple was built to honor Lord Shiva and its original name was Shiva-grha (the House of Shiva) or Shiva-laya (the Realm of Shiva).According to Shivagrha inscription, a public water project to change the course of a river near Shivagrha Temple was conducted during the construction of the temple. The river, identified as the Opak River, now runs north to south on the western side of the Prambanan temple compound. Historians suggest that originally the river was curved further to east and was deemed too near to the main temple.[citation needed] The project was done by cutting the river along a north to south axis along the outer wall of the Shivagrha Temple compound. The former river course was filled in and made level to create a wider space for the temple expansion, the space for rows of pervara (complementary) temples.