Fix variable assignment before second loop