First version that works for inference algorithm