fixed toArray method