fixing potential infinite loop