it seem to not work correctly inside for loop