added flat each and flat reduce