finished function for populating list or selection elements