prevent infinite while loop