Fix var ref and add debugging