Updated toArray method. Added do parameter into tests.