generalize for arrays