Fix the error caused by the callback in loop