Imported from https://github.com/rloganiv/kglm-model