Variable overwritten in loop & old namespace reference