Improvement and generalization of ABCD method with Bayesian inference