change O(N) to O(n)