updated toArray and added, finally, unit testing