used recursive function to create array to list function