Changed some of the indexing of the i,j loops (slower for now)