Fix var scoping and typos