handle infinite loop