Can be optimized to N*N