fixed a couple of bugs and made code more uniform
major refactoring and added the abillity to specify whether we're looking at a sampled distribution or not