initial commit. Mostly copied code from hsmm