fix to make O(n^2)