fix dead loop problem