Fix a nasty bug caused by incorrect variable shadowing