Imported code from the abcsp research project.