Added automatical calculation of likelihood function of X*Y and some refactoring