fixing infinite loops