ISSUE 89, 90: fixed wrong index count causing infinite loop