fixing infinite loop