Imported from https://github.com/neurodata/mgc-r