Changet toArray implementation