added toarray function