Removed extra for statement, which resulted in the variable name i being used twice.