refactored distmatrix from beta model single inst for speed-up and better handling