cleaned up and encapsulated mcmc code