changed arrays to vectors so that they won't take up O(n) stack space