Add condition to avoid infinite loop.