fix a bug which can lead into an infinity loop.