Fixing embarassing failure regarding variable scoping