bug fixes in variable lookup generation