Fix a bug of infinity-loop