fix edge case with infinite loop