BUG: Math on size_t is unsigned, so the first loop was not using the correct bounds.