Updated counter i which caused an infinite loop.