Working algorithm up to the point where it won't compute the last column