some refactoring and crucial bug fix in prob inference