added and tested optimized all pairs weak