fix loop bug