created populate middle function