Streamlined the inference code to make it more comprehensible