Corrected the loop counter. close #359