cloning from official opengm repo