fix encoding regression caused by shadowing variables and some typos