fixed a bug where there is an infinite loop