expanded the multivariate case, now it works almost flawlessly