Fix the memory leak that was incorrectly iterating rows and columns