BUGFIX: variable was redefined every time, now it's clear it comes from outside the loop