including nested sampler function + others

nearly ready to actually try this code.
added last bit of indexing

probably doesn't work, but we'll see.