update to O(n)