Imported from https://github.com/ctr4si/MMN