fix bug that causes infinite loop due to broken data