Modified to use array instead of vector.