Fixing iteration through similarity matrix.