Fixing HMC bugs, introducing tests. Still need some more tests, though.