printMiddle function added