Add global flatten and each functions