changed N+1 to N everywhere.