Fix bug that causes infinite loop in debug mode