trying to fix the loop crash problem