changed to print list only at end