updated inference code