Imported code from the Arit project