fix iteration loop to stop after reading the last column instead of before